package ldwu.spark.guess

/**
 * Created by liangdong.wu on 2016/10/11.
 */
import org.apache.spark.mllib.recommendation.Rating

object ParseUserAction {
  def parseLine(str: String) : (String, String, Double, Long) = {
    val fields = str.split(",")
    if ( fields.size == 4 ) {
      try {
        (fields(0), fields(1), fields(2).toDouble, fields(3).toLong)
      } catch {
        case e:Throwable => ("", "", 0.0f, 0L)
      }
    } else {
      ("", "", 0.0f, 0L)
    }
  }

  def parseRating(rating: ((String, String), Double)) = {
    ((rating._1._1, rating._1._2), Rating(rating._1._1.hashCode, rating._1._2.hashCode, rating._2))
  }
}